<template>
  <div id="app">
    <a-input @change="handleInputChange" :value="inputValue" placeholder="请输入任务" class="my_ipt" />
    <a-button ref="anniu" type="primary" @click="addList">添加事项</a-button>

    <a-list bordered :dataSource="list" class="dt_list">
      <a-list-item slot="renderItem" slot-scope="item">
        <!-- 复选框 -->
        <a-checkbox :checked="item.done" @change="(e)=>{cbStatusChanged(e,item.id)}">{{ item.info }}</a-checkbox>
        <!-- 删除链接 -->
        <a slot="actions" @click="deleteList(item.id)">删除</a>
      </a-list-item>

      <!-- footer区域 -->
      <div class="footer" slot="footer">
        <span>{{unDoneLength}}条剩余</span>
        <a-button-group>
          <a-button type="primary">全部</a-button>
          <a-button type="default">未完成</a-button>
          <a-button type="default">已完成</a-button>
        </a-button-group>
        <a @click="clean">清除已完成</a>
      </div>
    </a-list>
  </div>
</template>
<script>
import { mapState, mapGetters } from 'vuex'
export default {
  name: 'app',
  data() {
    return {}
  },
  computed: {
    ...mapState(['list', 'inputValue']),
    ...mapGetters(['unDoneLength'])
  },
  created() {
    this.$store.dispatch('getList')
  },
  methods: {
    handleInputChange(e) {
      this.$store.commit('SETINPUTVALUE', e.target.value)
    },
    addList() {
      if (this.inputValue.trim().length <= 0) {
        return this.$message.warning('啥都没写兄弟！！！')
      }
      this.$store.commit('ADDITEM')
    },
    deleteList(id) {
      this.$store.commit('DELETEITEM', id)
    },
    cbStatusChanged(e, id) {
      const param = {
        id: id,
        status: e.target.checked
      }
      this.$store.commit('CHANGESTATUS', param)
    },
    clean() {
      this.$store.commit('CLEANDONE')
    }
  }
}
</script>
<style scoped>
#app {
  padding: 10px;
}
.my_ipt {
  width: 500px;
  margin-right: 10px;
}
.dt_list {
  width: 500px;
  margin-top: 10px;
}
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
